﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerApplication.PeerManager
{

    class CurrentStatus
    {
        private float mPreviousFrameRate;
        private float mFrameRate;
        private int mLocalPoints;
        private int mNetworkPoints;
        private string mPosition;
        private string mIpPortRepresentation;
        private string mFrameRateSatus;

        public string IpPortRepresentation
        {
            get
            {
                return mIpPortRepresentation;
            }

            set
            {
                mIpPortRepresentation = value;
            }
        }

        public int LocalPoints
        {
            get 
            { 
                return mLocalPoints; 
            }

            set 
            { 
                mLocalPoints = value; 
            }
        }

        public int NetworkPoints
        {
            get
            {
                return mNetworkPoints;
            }

            set
            {
                mNetworkPoints = value;
            }
        }


        public string FrameRateStatus 
        {
            get 
            {
                return mFrameRateSatus;
            }

            set 
            {
                mFrameRateSatus = value;
            }
        }

        public float FrameRate
        {
            get
            {
                return mFrameRate;
            }

            set
            {
                mFrameRate = value;
            }
        }


        public CurrentStatus(string pInputString)
        {
            mPreviousFrameRate = 0;
            mFrameRate = 0;
            mLocalPoints = 0;
            mNetworkPoints = 0;
            mPosition = "0,0,0";

            IpPortRepresentation = pInputString;
        }

        public void FromString(string pNewStatus)
        {
            mFrameRateSatus = "";
            mPreviousFrameRate = mFrameRate;
            string[] tempArray = pNewStatus.Split(',');
            mLocalPoints = Convert.ToInt32(tempArray[0]);
            mNetworkPoints = Convert.ToInt32(tempArray[1]);
            float.TryParse(tempArray[2], out mFrameRate);
            mPosition = tempArray[3];
            SetFrameRateSatus();
        }

        private void SetFrameRateSatus()
        {
            if (mFrameRate > mPreviousFrameRate)
                mFrameRateSatus = "inc";
            else if (mFrameRate < mPreviousFrameRate)
                mFrameRateSatus = "dec";
            else
                mFrameRateSatus = "---";
        }

    }
}
